package com.zjp.aop.service;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.RandomUtil;
import com.zjp.aop.annotation.Log;
import com.zjp.aop.core.LogContext;
import com.zjp.aop.domain.UserLog;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class LogService {


    @Log(content = "userId:[#obj.userId] dataLogId:[#obj.dataLogId] ", bizNo = "bizNo")
    public void test(UserLog obj) {
        LogContext.putVariable("bizNo", DateUtil.format(new Date(), DatePattern.PURE_DATETIME_PATTERN) + RandomUtil.randomString(5));
    }

    @Log(content = "a1:[#a1] a2:[#a2] ", bizNo = "bizNo")
    public String test1(String a1, String a2) {
        String s = a1 + "---" + a2;
        String simpleUUID = IdUtil.simpleUUID();
        LogContext.putVariable("bizNo", simpleUUID);

        System.out.println(s + "--test1--bizNo-" + simpleUUID);

        return s;
    }

    @Log(content = "[#date]【[#name]】 放款 【[#a1]】元 [#addOne('[#a1]')]", bizNo = "bizNo")
    public String test2(String date, String name, Integer a1) {
        String simpleUUID = IdUtil.simpleUUID();
        System.out.println("test2---" + simpleUUID);
        LogContext.putVariable("bizNo", simpleUUID);
        //SpringUtils.getAopProxy(this).test1("123", "321");
        return String.format("%s【%s】 放款 【%d】元", date, name, a1);
    }


    public static String addOne(String str) {
        return str + "111";
    }

}
